import Vue from 'vue'
import VueRouter from 'vue-router'
import visitorindex from '../views/visitorindex.vue'
import index from '../views/index.vue'
import Log from '../views/Log.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Log',
    component: Log,
    meta: {
      title: "登录"
    }
  },
  {
    path: '/log',
    name: 'Log',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Log.vue'),
    meta: {
      title: "登录"
    }
  },
  {
    path: '/index',
    name: 'index',
    component: index,
    children: [
       {
        path: '/visitorindex',
        name: 'visitorindex',
        component: () =>
          import('../views/visitorindex')
      },
      // 管理员
      {
        path: '/admin',
        name: 'admin',
        component: () =>
          import('../views/admin'),
          meta: {
            title: "管理员"
          }
      },
      // 部门管理
      {
        path: '/section',
        name: 'section',
        component: () =>
          import('../views/section'),
          meta: {
            title: "部门管理"
          }
      },
      // 访客记录
      {
        path: '/visitor',
        name: 'visitor',
        component: () =>
          import('../views/visitor'),
          meta: {
            keepAlive: true,
            title: "访客记录"
          }
      },
      // 审核日志
      {
        path: '/auditlog',
        name: 'auditlog',
        component: () =>
          import('../views/auditlog'),
          meta: {
            title: "审核日志"
          }
      },
      // 核销人员管理
      {
        path: '/reviewer',
        name: 'reviewer',
        component: () =>
          import('../views/reviewer'),
          meta: {
            title: "核销人员管理"
          }
      },
      // 校园动态
      {
        path: '/news',
        name: 'news',
        component: () =>
          import('../views/news'),
          meta: {
            title: "校园动态"
          }
      },
      {
        path: '/Newsdetails',
        name: 'Newsdetails',
        component: () =>
          import('../components/Newsdetails'),
          meta: {
            title: "校园动态详情"
          }
      },
      {
        path: '/VisitorRecordDetails',
        name: 'VisitorRecordDetails',
        component: () =>
          import('../components/VisitorRecordDetails'),
          meta: {
            title: "访客详情"
          }

      },
      {
        path: '/AuditLogDetails',
        name: 'AuditLogDetails',
        component: () =>
          import('../components/AuditLogDetails'),
          meta: {
            title: "来访人详情"
          }
      },
      {
        path: '/Verificationpersonneldetails',
        name: 'Verificationpersonneldetails',
        component: () =>
          import('../components/Verificationpersonneldetails'),
          meta: {
            title: "核销详情"
          }
      },
    ]
  },
]

const router = new VueRouter({

  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// router/index.js
let routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {

  let history = this.currentRoute && this.currentRoute.fullPath;
  if (location === history) {
    this.app.reloadChild && this.app.reloadChild();
  }
  return routerPush.call(this, location).catch(err => err)
}
router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  // console.log(to);
  // console.log(from);
  next();
})
export default router
